package com.example.lixudongdazuoye.component;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.example.lixudongdazuoye.R;

//在这里形成好友栏边框字母栏，应用于fragment_friends

public class SideBar extends androidx.appcompat.widget.AppCompatTextView {
    private Paint textPaint;
    private Paint bigTextPaint;
    private Paint scaleTextPaint;
    private Canvas canvas;
    private int itemH;
    private int w;
    private int h;
    float singleTextH;//普通情况下字体大小
    private float scaleWidth;//缩放离原始的宽度
    private float eventY = 0;//滑动的Y
    private int scaleSize = 1;//缩放的倍数
    private int scaleItemCount = 6; //缩放个数item，即开口大小，一个字母下的最多人数
   // private ISideBarSelectCallBack callBack;
    public SideBar(Context context) {
        this(context, null);
    }
    public SideBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
    public SideBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs);//AttributeSet接受attrs，然后调用下面的函数
    }

    private void init(AttributeSet attrs) {
        if (attrs != null) {
            TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.SideBar);//创造ta变量，获取xml信息
            scaleSize = ta.getInteger(R.styleable.SideBar_scaleSize, 1);//具体由这三个接收
            scaleItemCount = ta.getInteger(R.styleable.SideBar_scaleItemCount, 6);
            scaleWidth = ta.getDimensionPixelSize(R.styleable.SideBar_scaleWidth, dp(100));
            ta.recycle();
        }
        textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        textPaint.setColor(getCurrentTextColor());//文字颜色
        textPaint.setTextSize(getTextSize());//文字大小
        textPaint.setTextAlign(Paint.Align.CENTER);//文字位于中间
        bigTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        bigTextPaint.setColor(getCurrentTextColor());
        bigTextPaint.setTextSize(getTextSize() * (scaleSize + 3));//需要更大的字
        bigTextPaint.setTextAlign(Paint.Align.CENTER);
        scaleTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        scaleTextPaint.setColor(getCurrentTextColor());
        scaleTextPaint.setTextSize(getTextSize() * (scaleSize + 1));
        scaleTextPaint.setTextAlign(Paint.Align.CENTER);
    }
    private int dp(int px) {
        final float scale = getContext().getResources().getDisplayMetrics().density;
        return (int) (px * scale + 0.5f);
    }
}